package fts.ftsdata.domain.impl;

import fts.ftsdata.domain.ITag;


public class Tag implements ITag
{
	private static String tagValidatorExpr = "[a-zA-Z0-9 _-]+";
	private String name;
	private Integer idTag;
	
	public Tag()
	{
	}
	
	public Tag(String name) throws Exception
	{
		System.out.println(Thread.currentThread().getStackTrace()[1]);
		
		assertTagName(name);
		this.name = name;
	}

	public static void assertTagName(String name) throws Exception
	{
		if(!validateTagName(name))
		{
			throw new Exception("Invalid tag name \""+name+"\".");
		}
	}
	
	public static boolean validateTagName(String name)
	{
		return name != null && name.matches(tagValidatorExpr);
	}
	
	public String getName()
	{
		return name;
	}

	public void setName(String name)
	{
		this.name = name;
	}

	public void setIdTag(Integer idTag)
	{
		this.idTag = idTag;
	}

	public Integer getIdTag()
	{
		return idTag;
	}

	@Override
	public int hashCode()
	{
		final int prime = 31;
		int result = 1;
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj)
	{
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Tag other = (Tag) obj;
		if (name == null)
		{
			if (other.name != null)
				return false;
		}
		else if (!name.equals(other.name))
			return false;
		return true;
	}


}
